<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>
<script type="text/javascript" src="<%=basePath%>js/initPage.js"></script>
<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">
<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
<!-- bootstrap-wysiwyg -->
<link
	href="<%=basePath%>vendors/google-code-prettify/bin/prettify.min.css"
	rel="stylesheet">
<!-- Select2 -->
<link href="<%=basePath%>vendors/select2/dist/css/select2.min.css"
	rel="stylesheet">
<!-- Switchery -->
<link href="<%=basePath%>vendors/switchery/dist/switchery.min.css"
	rel="stylesheet">
<!-- starrr -->
<link href="<%=basePath%>vendors/starrr/dist/starrr.css"
	rel="stylesheet">
</head>
<%@ include file="loginCheck.jsp"%>
<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">
					<div class="clearfix"></div>
					<br />
				</div>
			</div>
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left"></div>
						<div class="x_content">
							<select class="btn btn-default dropdown-toggle" id="category"
								style="text-align: center;">
								<option value="18"
									<c:if test="${category == 18}">selected</c:if>>全部分类</option>
								<option value="0" <c:if test="${category == 0}">selected</c:if>>头条</option>
								<c:if test="${shehui != null}">
								<option value="1" <c:if test="${category == 1}">selected</c:if>>社会</option></c:if>
								<c:if test="${guonei != null}">
								<option value="2" <c:if test="${category == 2}">selected</c:if>>国内</option></c:if>
								<c:if test="${guoji != null}">
								<option value="3" <c:if test="${category == 3}">selected</c:if>>国际</option></c:if>
								<c:if test="${yule != null}">
								<option value="4" <c:if test="${category == 4}">selected</c:if>>娱乐</option></c:if>
								<c:if test="${tiyu != null}">
								<option value="5" <c:if test="${category == 5}">selected</c:if>>体育</option></c:if>
								<c:if test="${junshi != null}">
								<option value="6" <c:if test="${category == 6}">selected</c:if>>军事</option></c:if>
								<c:if test="${keji != null}">
								<option value="7" <c:if test="${category == 7}">selected</c:if>>科技</option></c:if>
								<c:if test="${caijing != null}">
								<option value="8" <c:if test="${category == 8}">selected</c:if>>财经</option></c:if>
								<c:if test="${shishang != null}">
								<option value="9" <c:if test="${category == 9}">selected</c:if>>时尚</option></c:if>
								<c:if test="${youxi != null}">
								<option value="10"
									<c:if test="${category == 10}">selected</c:if>>电竞</option></c:if>
								<c:if test="${qiche != null}">
								<option value="11"
									<c:if test="${category == 11}">selected</c:if>>汽车</option></c:if>
								<c:if test="${xiaohua != null}">
								<option value="12"
									<c:if test="${category == 12}">selected</c:if>>笑话</option></c:if>
								<c:if test="${jiankang != null}">
								<option value="13"
									<c:if test="${category == 13}">selected</c:if>>健康</option></c:if>
								<c:if test="${jiaju != null}">
								<option value="14"
									<c:if test="${category == 14}">selected</c:if>>生活</option></c:if>
								<c:if test="${xingzuo != null}">
								<option value="15"
									<c:if test="${category == 15}">selected</c:if>>星座</option></c:if>
								<c:if test="${lishi != null}">
								<option value="16"
									<c:if test="${category == 16}">selected</c:if>>历史</option></c:if>
								<c:if test="${zatan != null}">
								<option value="17"
									<c:if test="${category == 17}">selected</c:if>>杂谈</option></c:if>
							</select>
							 新闻标题: <input type="text" id="newstitle" value="${title}" /> 
							 来源: <input type="text" id="newsfrom" value="${from}" /> 
							 新闻日期: <input type="text" id="newsdate" value="${date}" />
							<button type="submit" class="btn btn-default"
								onclick="selectALL('1')">搜索</button>
						</div>
					</div>
					<div class="x_panel">
						<div class="x_content">
							<table id="datatable" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th>新闻标题</th>
										<th>分类</th>
										<th>新闻日期</th>
										<th>来源</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${news}" var="s" varStatus="z">
										<tr>
											<td>${s.title }</td>
											<td>${s.type}</td>
											<td><fmt:formatDate value="${s.date}" type="date"
													pattern="yyyy-MM-dd" /></td>
											<td>${s.from}</td>
											<td><a href="javascript:" type="submit"
                                                   class="btn btn-success"
                                                   onclick="content_xinwenxiangqing('${s.id}')">查看详情</a>
												<button type="submit" class="btn btn-default"
															id="delect" onclick="delectNews('${s.id}')">删除</button></td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
					<div class="clearfix"></div>
					<br />
				</div>
				<div style="width: 100%; text-align: center;">
					<div id='page'></div>
				</div>
			</div>
		</div>
	</div>
	<!-- /page content -->
	<!-- /page content -->
	<script>
		/**
		 * 纯粹的JS分页插件，代码缺点：JS操作DOM冗余太多，太繁琐
		 */
		 pageUtil.initPage('page', {
				totalCount : '${totlenum}', //总页数，一般从回调函数中获取。如果没有数据则默认为1页
				curPage : ${curPage}, //初始化时的默认选中页，默认第一页。如果所填范围溢出或者非数字或者数字字符串，则默认第一页
				showCount : 9, //分页栏显示的数量
				pageSizeList : [ 10 ], //自定义分页数，默认[5,10,15,20,50]
				defaultPageSize : 10, //默认选中的分页数,默认选中第一个。如果未匹配到数组或者默认数组中，则也为第一个
				isJump : true, //是否包含跳转功能，默认false
				isPageNum : true, //是否显示分页下拉选择，默认false
				isPN : true, //是否显示上一页和下一面，默认true
				isFL : true, //是否显示首页和末页，默认true
				jump : function(curPage, pageSize) { //跳转功能回调，传递回来2个参数，当前页和每页大小。如果没有设置分页下拉，则第二个参数永远为0。这里的this被指定为一个空对象，如果回调中需用到this请自行使用bind方法
					selectALL(curPage);
				},
			});		 
	</script>
	<script type="text/javascript">
	function selectALL(curPage) {
		var newstitle = $("#newstitle").val();
		var newsfrom = $("#newsfrom").val();
		var newsdate = $("#newsdate").val();
		var category = $("#category").find("option:selected").val();
		location.href = "selectNews?title=" + newstitle +
			"&curPage=" + curPage +
			"&date=" + newsdate +
			"&category=" + category +
			"&from=" + newsfrom;
	}
	
	function content_xinwenxiangqing(id) {
		location.href = "content_xinwencaozuo?id=" + id;
	}
	</script>
	<script>
	function ajaxObject() {
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					alert("您的浏览器不支持AJAX！");
					return false;
				}
			}
		}
		return xmlHttp;
	}
	
	function delectNews(id) {
		alert("暫未開放");
		return false;
		if(!confirm("确认要删除吗，此操作不可撤销")){
			return false;
		}
		var ajax = ajaxObject();
		ajax.open("post", "updateNews?id=" + id +
				"&datastatus" + 0, false);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var result = ajax.responseText;
					if (result == "success") {
						//请求成功
						alert("删除成功");
						location.href = "content_xinwenliebiao";
					} else {
						//请求成功
						alert(result);
						location.href = "content_xinwenliebiao";
					}
				}else{
					//请求失败
					alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
				}
			} else {

			}
		};
		ajax.send();
	}
	</script>
	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- iCheck -->
	<script src="<%=basePath%>vendors/iCheck/icheck.min.js">
	</script>
	<!-- bootstrap-wysiwyg -->
	<script
		src="<%=basePath%>vendors/bootstrap-wysiwyg/js/bootstrap-wysiwyg.min.js"></script>
	<script src="<%=basePath%>vendors/jquery.hotkeys/jquery.hotkeys.js"></script>
	<script src="<%=basePath%>vendors/google-code-prettify/src/prettify.js"></script>
	<!-- jQuery Tags Input -->
	<script
		src="<%=basePath%>vendors/jquery.tagsinput/src/jquery.tagsinput.js"></script>
	<!-- Switchery -->
	<script src="<%=basePath%>vendors/switchery/dist/switchery.min.js"></script>
	<!-- Select2 -->
	<script src="<%=basePath%>vendors/select2/dist/js/select2.full.min.js"></script>
	<!-- Parsley -->
	<script src="<%=basePath%>vendors/parsleyjs/dist/parsley.min.js"></script>
	<!-- Autosize -->
	<script src="<%=basePath%>vendors/autosize/dist/autosize.min.js"></script>
	<!-- jQuery autocomplete -->
	<script
		src="<%=basePath%>vendors/devbridge-autocomplete/dist/jquery.autocomplete.min.js"></script>
	<!-- starrr -->
	<script src="<%=basePath%>vendors/starrr/dist/starrr.js"></script>
	<!-- layui -->
	<script src="<%=basePath%>vendors/layui/layui.js"></script>
</body>
</html>